package Model
{
	import flash.net.SharedObject;
	
	[Bindable]
	public class Config
	{
		private static var _instance:Config;
		
		public static const REMOTE_URL:String = "http://www.example.com/NginxStatus";
		public static const ITEM_LENGTH:Number = 20;
		public static const TIME_DELAY:Number = 1000;
		
		private var _remoteUrl:String = REMOTE_URL;
		private var _itemLength:Number = ITEM_LENGTH;
		private var _timeDelay:Number = TIME_DELAY;
		
		private var _so:SharedObject = SharedObject.getLocal("nginx_monitor");
		
		public function Config()
		{			
		}
		
		public static function getInstance():Config {
			if ( !_instance ) {
				return _instance = new Config();
			}
			
			return _instance;
		}
		
		public function initDefault():void {
			remoteUrl = REMOTE_URL;
			itemLength = ITEM_LENGTH;
			timeDelay = TIME_DELAY;
		}

		public function get remoteUrl():String
		{
			if ( _so.data.remoteUrl ) {
				return _so.data.remoteUrl;
			}
			
			return _remoteUrl;
		}

		public function set remoteUrl(value:String):void
		{
		//	_remoteUrl = value;
			_so.data.remoteUrl = value;
		}

		public function get itemLength():Number
		{
			if ( _so.data.itemLength ) {
				return _so.data.itemLength;
			}
			
			return _itemLength;
		}

		public function set itemLength(value:Number):void
		{
		//	_itemLength = value;
			_so.data.itemLength = value;
		}

		public function get timeDelay():Number
		{
			if ( _so.data.timeDelay ) {
				return _so.data.timeDelay;
			}
			
			return _timeDelay;
		}

		public function set timeDelay(value:Number):void
		{
		//	_timeDelay = value;
			_so.data.timeDelay = value * 1000;
		}


	}
}